﻿
function AddClientAddFocusNews()
{
    belongSite=document.getElementById("drpSelectSiteForFocusNews").options[document.getElementById("drpSelectSiteForFocusNews").selectedIndex].value;
    Url = Portal.CMS.FocusNews.GetAddFocusNewsUrl(belongSite).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }

    //window.showModalDialog(Url, "", "dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;");
    window.open(Url, '_blank');
    //FilterFunc();
}

function ClientSaveAddFocusNews() {
    SelectLanguageForFocusNewsIndex = document.getElementById("divSelectLanguageForFocusNews").selectedIndex;
    SelectLanguageForFocusNews = document.getElementById("divSelectLanguageForFocusNews").options[SelectLanguageForFocusNewsIndex].value;
    belongSite=document.getElementById("txtBelongSite").value;
    Subject = document.getElementById("txtFocusNews").value;
    retValue = Portal.CMS.AddFocusNews.ServerSideAddFocusNews(belongSite, SelectLanguageForFocusNews, Subject).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}


function ClientDeleteFocusNews(FocusNewsId) {
    
    retValue=Portal.CMS.FocusNews.ServerSideCheckAllowDelete(FocusNewsId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    
    Msg=Portal.CMS.FocusNews.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.CMS.FocusNews.ServerSideDeleteFocusNews(FocusNewsId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
   FilterFunc();
}

function ShowClientUpdateUrlForm(FocusNewsId)
{
    Url=Portal.CMS.FocusNews.GetShowUpdateForm(FocusNewsId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientSaveUpdateFocusNews(FocusNewsId)
{
    Subject=document.getElementById("txtFocusNews").value;
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
 
    RetValue = Portal.CMS.UpdateFocusNews.ServerSideUpdateFocusNews(language,FocusNewsId,Subject).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}


function ShowClientFocusNewsItemUrlForm(FocusNewsId) {
    Url = Portal.CMS.FocusNews.GetShowFocusNewsItemsForm(FocusNewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function FilterFunc() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.FocusNews.GetProcessingText().value;
    setTimeout("RealFilterFunc()", 10);
}


function RealFilterFunc() {
    belongSite = document.getElementById("drpSelectSiteForFocusNews").options[document.getElementById("drpSelectSiteForFocusNews").selectedIndex].value;
    retValue = Portal.CMS.FocusNews.GetHtml(belongSite).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divFocusNewsMain").innerHTML = retValue;
}








function ClientSearchFocusNews() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.FocusNewsItem.GetProcessingText().value;
    setTimeout("RealClientSearchFocusNews()", 10);
}

function RealClientSearchFocusNews() {
    FocusNewsId = document.getElementById("txtFocusNewsId").value;
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    Keyword = document.getElementById("txtSearchKeyword").value;
    fromDate = document.getElementById("txtFromDate").value;
    toDate = document.getElementById("txtToDate").value;
    belongSiteIndex = document.getElementById("drpSelectSiteForSearchNews").selectedIndex;
    belongSite = document.getElementById("drpSelectSiteForSearchNews").options[belongSiteIndex].value;
    GroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    Source = document.getElementById("txtSource").value;
    PageIndex = 0;
    if (document.getElementById("divSelectSearchNewsPage") != null) {
        PageIndex = document.getElementById("divSelectSearchNewsPage").selectedIndex;
    }

    retValue = Portal.CMS.FocusNewsItem.SearchFocusNews(FocusNewsId, belongSite, Keyword, fromDate, toDate, WorkflowStatusIndex, GroupNewsItemId, Source, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divSearchNewsContent").innerHTML = retValue;
}


function ClientAddFocusNews(NewsId) {
    FocusNewsId = document.getElementById("txtFocusNewsId").value;
    retValue = Portal.CMS.FocusNewsItem.ServerSideAddFocusNewsItem(FocusNewsId, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
    }
    else {
        alert("Đưa tin vào nhóm tiêu điểm thành công!");
        document.getElementById("divAddFocusNewsItem_" + NewsId).innerHTML = "";
        document.getElementById("divAlreadyFocusNews").innerHTML = retValue;
    }
}

function ClientRemoveFocusNews(FocusNewsItemId) {
    if (confirm("Bạn đã chắc chắn chưa?") == false) return;
    FocusNewsId = document.getElementById("txtFocusNewsId").value;
    retValue = Portal.CMS.FocusNewsItem.ServerSideRemoveFocusNewsItem(FocusNewsId, FocusNewsItemId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
    }
    else {
        alert("Loại bỏ tin ra khỏi nhóm tiêu điểm thành công!");
        document.getElementById("divAlreadyFocusNews").innerHTML = retValue;
    }
}

function ShowUpdateNewsForm(GroupNewsId, GroupNewsItemId, NewsId) {
    Url = Portal.CMS.FocusNewsItem.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientSaveIndex(FocusNewsItemsId) {
    SortIndex = document.getElementById("txtIndex" + FocusNewsItemsId).value;
    Url = Portal.CMS.FocusNewsItem.ServerSideSaveIndex(FocusNewsItemsId, SortIndex).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    alert(Url);
}

function ClientSyncWithServer(FocusNewsId) {
    rValue = Portal.CMS.FocusNews.ServerSideSyncWithServer(FocusNewsId).value;
    alert(rValue);
}